<template>
  <div id="player">
    <el-carousel :interval="4000" type="card" height="200px">
      <el-carousel-item
        v-for="(item, index) in banners"
        :key="'banner' + index"
      >
        <el-image
          :src="item.imageUrl"
          fit="cover"
          style="width: 600px; height: 200px"
        />
      </el-carousel-item>
    </el-carousel>
    <div class="search">
      <input type="text" v-model.trim="keyword" @keyup.enter="searchMusic" />
      <button>
        <span class="iconfont icon-search" @click="searchMusic"></span>
      </button>
    </div>
    <div class="tab-wrapper">
      <!-- tab栏 -->
      <!-- <div class="tab-bar">
        <router-link to="/results" class="bar-item" active-class="active">搜索结果</router-link>
        <router-link to="/player" class="bar-item" active-class="active">歌曲播放</router-link>
        <router-link to="/mv" class="bar-item" active-class="active">视频播放</router-link>
        <router-link to="/com" class="bar-item" active-class="active">歌曲评论</router-link>
      </div> -->
      <!-- 对应的内容区域 -->
      <div class="tab-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>
<script>
// import axios from "axios";
export default {
  data() {
    return {
      keyword: "",
      banners: [],
    };
  },
  async created() {
    let res = await this.$axios.get("/banner");
    console.log(res.data.banners);
    this.banners = res.data.banners;
  },
  methods: {
    searchMusic() {
      if (!this.keyword) {
        // alert("搜索内容不允许为空！")
        this.$message({
          message: "搜索内容不允许为空",
          type: "error",
        });
        return;
      }
      this.$router.push("/results/" + this.keyword);
    },
  },
};
</script>
<style scoped>
/* scoped 确保当前 css 只在当前作用域内生效，自定义的随机增加了一个 属性 进行控制 */
/* 在 内部使用 import 导入，scoped 效果并没有真实生效 */
@import url("./assets/css/index.css");
@import url("./assets/css/iconfont.css");
</style>